﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Mavin;
using PowerCreator.LMS.Mavin.Entity;

public partial class sysadmin_mavinManager_addmavin : PowerCreator.LMS.Web.Base.BasePage
{
    Mavin objMavin = new Mavin();
    public int MavinID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
            if (Request.QueryString["MavinID"] != null)
            {
                MavinID = int.Parse(Request.QueryString["MavinID"].ToString());
                if (MavinID != 0)
                {
                    ViewState["MavinID"] = MavinID.ToString();
                    BinderForm(MavinID);
                }
                if (Request.QueryString["AddMavin"] != null)
                {
                    if (Request.QueryString["AddMavin"].ToString() == "upload")
                    {
                        string path = Request.QueryString["fullpath"].ToString();
                        txt_MavinUrl.Text = path;
                        ViewState["filesize"] = Request.QueryString["filesize"];
                    }
                }
            }
        }
    }
    protected override void InitPage()
    {
        //lbl_InfoTitle.Text = GetLanageValueByKey("lbl_AddJob_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobName.Text = GetLanageValueByKey("lbl_AddJob_JobName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobDescription.Text = GetLanageValueByKey("lbl_AddJob_JobDescription", PowerCreator.LMS.Language.LanagetItemType.Page);

        //btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        //btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        //base.InitPage();

        //lbl_InfoTitle_AddDownload.Text = GetLanageValueByKey("lab_AddDownload_DownloadTypeName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_DownloadUploadInfo.Text = GetLanageValueByKey("lab_AddDownload_ResourseFileUplaod", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_DownloadFileUrl.Text = GetLanageValueByKey("lab_AddDownload_ResourseFile", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_DownloadBaseInfo.Text = GetLanageValueByKey("lab_AddDownload_ResourseInfoSet", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_DownloadName.Text = GetLanageValueByKey("lbl_ResourceList_ResourceName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_FKDownDownTypeID.Text = GetLanageValueByKey("lbl_AddResourceInfo_ResourceClass", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_DownEdition.Text = GetLanageValueByKey("lab_AddDownload_SoftVersionNumber", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_AddDownload_msg_DownEdition.Text = GetLanageValueByKey("msg_AddDownload_msg1", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_DownDescription.Text = GetLanageValueByKey("lab_AddDownload_ResourseDes", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_DownState.Text = GetLanageValueByKey("lab_AddDownload_ResourseState", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_DownloadPictureUrl.Text = "图片";
        //lbl_DownloadPictureUrl_intro.Text = "只有在前台页面做特殊展示，例如做图片新闻时才需上传！";

        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }

    private void BinderForm(int id)
    {
        VOTMavin vo = new VOTMavin();
        vo = objMavin.Load(id);

        txt_MavinUrl.Text = vo.MavinPic;
        txt_MavinName.Text = vo.MavinName;
        txt_MavinDescription.Text = vo.MavinIntroduce;
        txt_MavinNationality.Text = vo.MavinNationality;
        txt_MavinStrongSuit.Text = vo.MavinStrongSuit;
        txtMavinJob.Text = vo.MavinJob;
        txt_MavinUnit.Text = vo.MavinUnit;

    }
    private bool CheckPageData()
    {
        string search = string.Format("MavinName = '{0}'", txt_MavinName.Text.Trim());
        if (ViewState["MavinID"] != null)
        {
            search += "and MavinID<>" + ViewState["MavinID"].ToString();
        }
        if (objMavin.Count(search) != 0)
        {

            //lbl_msg_Error.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_count", PowerCreator.LMS.Language.LanagetItemType.MSG);

            lbl_msg_Error.Text = "<br />" + GetLanageValueByKey("msg_AddDownload_Msg2", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        VOTMavin vo = new VOTMavin();
        if (ViewState["MavinID"] != null)
        {
            vo = objMavin.Load(int.Parse(ViewState["MavinID"].ToString()));
        }
        vo.MavinName = txt_MavinName.Text;
        vo.MavinJob = txtMavinJob.Text;
        vo.MavinNationality = txt_MavinNationality.Text;
        vo.MavinStrongSuit = txt_MavinStrongSuit.Text;
        vo.MavinIntroduce = txt_MavinDescription.Text;
        vo.MavinPic = txt_MavinUrl.Text;
        vo.MavinUnit = txt_MavinUnit.Text;

        if (ViewState["MavinID"] == null)
        {
            if (objMavin.Add(vo))
            {
                string url = "mavinManager.aspx";
                Script.RedirectURL(url);
            }
        }
        else
        {
            if (objMavin.Update(vo))
            {
                string url = "mavinManager.aspx";
                Script.RedirectURL(url);
            }
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "mavinManager.aspx";
        Script.RedirectURL(url);
    }

}
